package com.qidian.buy.config;

import org.springframework.amqp.core.AcknowledgeMode;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 戴着假发的程序员
 * @company 起点编程
 * @date 2023/9/15 11:45
 */
@Configuration
public class ItemIdListenerConfig {
    @Autowired
    private CachingConnectionFactory cachingConnectionFactory;

    @Autowired
    private ItemIdReceive myAckReceive;

    @Bean
    public SimpleMessageListenerContainer listenerContainer(){
        SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(cachingConnectionFactory);
        // 监听队列名
        container.setQueueNames("item-add-search");  // 可以在配置文件中配置
        // 当前消费者数量
        container.setConcurrentConsumers(1); // 建议在配置文件中配置
        // 最大消费者数量
        container.setMaxConcurrentConsumers(1);// 建议在配置文件中配置
        // 手动确认
        container.setAcknowledgeMode(AcknowledgeMode.MANUAL);
        // 设置监听器
        container.setMessageListener(myAckReceive);
        return container;
    }

}
